unit uPesquisaPadrao;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, IBODataset, Grids, DBGrids, RXDBCtrl, RXCtrls, StdCtrls,
  ExtCtrls, ComCtrls;

type
  TfPesquisaPadrao = class(TForm)
    Panel1: TPanel;
    Edit1: TEdit;
    RxLabel1: TRxLabel;
    RxDBGrid1: TRxDBGrid;
    query: TIBOQuery;
    DataSource: TDataSource;
    StatusBar1: TStatusBar;
    procedure RxDBGrid1DblClick(Sender: TObject);
    procedure RxDBGrid1KeyPress(Sender: TObject; var Key: Char);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure RxDBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure FormShow(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fPesquisaPadrao: TfPesquisaPadrao;

implementation

uses uPrincipal;

{$R *.dfm}

procedure TfPesquisaPadrao.RxDBGrid1DblClick(Sender: TObject);
begin
  ModalResult := mrOk;
end;

procedure TfPesquisaPadrao.RxDBGrid1KeyPress(Sender: TObject;
  var Key: Char);
begin
  if key = #13 then
    RxDBGrid1.OnDblClick(sender);
end;

procedure TfPesquisaPadrao.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if key = #27 then
    close;
end;

procedure TfPesquisaPadrao.RxDBGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin
  if odd(query.RecNo) then
    RxDBGrid1.Canvas.Brush.Color:= fPrincipal.linhaEscura
  else
    RxDBGrid1.Canvas.Brush.Color:= fPrincipal.linhaClara;

  TDbGrid(Sender).Canvas.font.Color:= clBlack;
    if gdSelected in State then
      with (Sender as TDBGrid).Canvas do
        begin
          Brush.Color := fPrincipal.linhaSelecionada;
          FillRect(Rect);
          Font.Style := [fsbold]
        end;

  TDbGrid(Sender).DefaultDrawDataCell(Rect, TDbGrid(Sender).columns[datacol].field, State);
end;

procedure TfPesquisaPadrao.FormShow(Sender: TObject);
begin
  query.close;
  query.Open;
  Edit1.SetFocus;
end;

procedure TfPesquisaPadrao.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if key = #13 then
    RxDBGrid1.SetFocus;
end;

end.
